package com.younion.action.consumer.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IMobileUpdateService;
import com.younion.model.AppUpdateResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.vo.ConfigVO;
import com.younion.vo.MobileUpdateVO;

public class AppUpdateConsumer extends AbstractRequestConsumer {
	private IMobileUpdateService mobileUpdateService = null;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getUpdateInfo(request, response);
	}

	public String getUpdateInfo(HttpServletRequest request,
			HttpServletResponse response) {
		AppUpdateResult appUpdateResult = new AppUpdateResult();
		MobileUpdateVO mobileUpdateVO = null;
		ResultObject resultObject = new ResultObject();
		Map paramMap = new HashMap();
		String clientType = request.getParameter("clientType");
		paramMap.put("clientType", clientType);
		try {
			mobileUpdateVO = mobileUpdateService.getApiByMap(paramMap);
			if (mobileUpdateVO != null) {
				appUpdateResult.setIsForceUpgrade(mobileUpdateVO
						.getIsForceUpgrade().toString());
				appUpdateResult.setVerAddress(mobileUpdateVO.getVerAddress());
				appUpdateResult.setVerCode(mobileUpdateVO.getVerCode());
				appUpdateResult.setVerSize(mobileUpdateVO.getVerSize());
				appUpdateResult.setVerText(mobileUpdateVO.getVerText());
			}
			resultObject.setResult(appUpdateResult);
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);
		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setMobileUpdateService(IMobileUpdateService mobileUpdateService) {
		this.mobileUpdateService = mobileUpdateService;
	}

}
